<template>
  <div>
    <el-dialog
      class="base-dialog"
      width="1300px"
      :custom-class="'panna-dialog_big'"
      :append-to-body="true"
      :title="title"
      align="center"
      :visible.sync="innerDialogFormVisible"
      :before-close="handleClose"
    >
      <MaterialRequisitionFormView
        :id.sync="id"
        ref="MaterialRequisitionFormView"
        :edit-state.sync="editState"
        :read-only.sync="readOnly"
      />
      <div v-if="!readOnly" slot="footer" class="dialog-footer" align="center">
        <el-button type="primary" @click="onSubmit">保 存</el-button>
        <el-button style="width: 100px" type="primary" @click="finish"
          >使用 完成</el-button
        >
        <el-button @click="handleClose">返 回</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import MaterialRequisitionFormView from "./MaterialRequisitionFormView.vue";
import {
  update,
  DisposeMaterialRequisitionForm,
} from "../../../api/Material/MaterialRequisitionFormDetails.js";
export default {
  name: "MaterialRequisitionFormViewDialog",
  components: {
    MaterialRequisitionFormView,
  },
  props: {
    dialogFormVisible: {
      type: Boolean,
      default: false,
    },
    editState: {
      type: Boolean,
      default: false,
    },
    id: {
      type: String,
      default: "",
    },
    readOnly: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      innerDialogFormVisible: false,
      title: "申领单详情",
    };
  },
  watch: {},
  created() {
    this.innerDialogFormVisible = this.dialogFormVisible;
    this.title = "申领单详情";
    if (this.editState && !this.readOnly) {
      this.title = "处理申领单";
    }
  },
  methods: {
    finish() {
      DisposeMaterialRequisitionForm(
        this.$refs.MaterialRequisitionFormView.formData
      ).then((res) => {
        this.handleClose();
      });
    },
    onSubmit() {
      update(
        this.$refs.MaterialRequisitionFormView.formData
          .requisitionFormDetailsList
      ).then((res) => {
        this.handleClose();
      });
    },
    handleClose() {
      this.$emit("close");
      this.$emit("update:dialogFormVisible", false);
      this.innerDialogFormVisible = false;
    },
  },
};
</script>

